package com.boat.framework.common.monitor.event;

import com.boat.framework.base.api.Response;
import com.boat.framework.base.exception.CommonErrorCode;
import com.boat.framework.common.util.ServletUtils;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
 * Controller接口被调用事件
 * 
 * 羽嘉框架已自动埋点，业务系统无需开发
 * 
 * @author 周江
 *
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class ControllerInvoked extends BaseMonitorEvent {
	/**
	 * 结果是否成功
	 */
	private Boolean success;
	/**
	 * 错误编码
	 */
	private String respCode;
	/**
	 * 错误描述
	 */
	private String respMsg;
	/**
	 * 耗时,单位毫秒
	 */
	private long times;
	/**
	 * 备注
	 */
	private String remark;

	public ControllerInvoked() {
		super();
	}

	public ControllerInvoked(long startTime, Response<?> response) {
		super();
		if (ServletUtils.getRequest() != null) {
			setName(ServletUtils.getRequest().getRequestURI());
		}
		
		// 计算耗时
		long betweenMs = System.currentTimeMillis() - startTime;
		setTimes(betweenMs);
		
		setRespCode(response.getCode());
		setRespMsg(response.getMessage());
		setSuccess(response.isSuccess());
		setRemark("Controller执行日志");
	}

}
